using Mvc.Mailer;
using CodeCamp.Models.Email;
using SNM = System.Net.Mail;

namespace CodeCamp.Mailers
{ 
    public class UserMailer : MailerBase, IUserMailer 	
	{
		public UserMailer()
		{
			MasterName="_Layout";
		}

        private string ActualSubject(EmailContentItem emailItem)
        {
            return emailItem.SubjectToUse;
        }

        private void AddToAddress(MvcMailMessage mailMessage, EmailContentItem emailItem)
        {
            string name = string.Format("{0} {1}", emailItem.FirstName, emailItem.LastName).Trim();
            string displayName = string.Format("{0} ({1})", name, emailItem.EmailTo);
            SNM.MailAddress toAddress = new SNM.MailAddress(emailItem.EmailTo, displayName);
            mailMessage.To.Add(toAddress);
        }

        //public virtual MvcMailMessage Basic(EmailContentItem emailItem)
        //{
        //    var mailMessage = new MvcMailMessage { Subject = ActualSubject(emailItem) };
        //    AddToAddress(mailMessage, emailItem);
        //    if (!string.IsNullOrWhiteSpace(emailItem.ReplyToAddress))
        //        mailMessage.ReplyToList.Add(emailItem.ReplyToAddress);

        //    ViewData = new System.Web.Mvc.ViewDataDictionary(emailItem);
        //    PopulateBody(mailMessage, emailItem.EmailView, null);
        //    return mailMessage;
        //}

        public virtual MvcMailMessage CodeCampEventMessage(EmailContentItem emailItem)
		{
            var mailMessage = new MvcMailMessage { Subject = ActualSubject(emailItem) };
            AddToAddress(mailMessage, emailItem);
            if (!string.IsNullOrWhiteSpace(emailItem.ReplyToAddress))
                mailMessage.ReplyToList.Add(emailItem.ReplyToAddress);

            ViewData = new System.Web.Mvc.ViewDataDictionary(emailItem);
            PopulateBody(mailMessage, emailItem.EmailView, null);
            return mailMessage;
        }
 	}
}